<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontHostname()+ServerValue.getFrontContextPath()%>'/>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1.5em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<link rel="stylesheet" type="text/css" href="/css/validator.css"/>
<!-- 時間 -->	
<script src="<%=ServerValue.getMidContextPath()%>/js/jquery.timePicker.js" type="text/javascript"/></script>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<link rel="stylesheet" type="text/css" href="/css/timePicker.css"/>
<script language="javascript">
$().ready( function(){

	$('#startDate').datepick({minDate: new Date(<%=request.getAttribute("eminDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
	$('#endDate').datepick({minDate: new Date(<%=request.getAttribute("eminDate").toString()%>),showOn: 'both',beforeShow:customRange,numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"});
	function customRange (){
		var startDt = $('#startDate').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}
	$("#startTime").timePicker();
	$("#endTime").timePicker({step:60, startTime:"00:59", endTime:"23:59"});
	$('#amount').numeric();
	$('#after').numeric();
	$('#days').numeric();

	if('${id}'==''){
		$("h1").eq(0).text('注册送积分或礼卷－新增');
	}
	if('${meType}'=='1'){
		$('#coupon').show();
		if($('#coupon_uuid').val().length!=0){
			loadCouponData();
		}
	}else{
		$('#bonus').show();
	}

	$('#radio_1').click(function(){//礼卷
		$('#coupon').show();
		$('#bonus').hide();
	});

	$('#radio_2').click(function(){
		$('#coupon').hide();
		$('#bonus').show();
	});

	$('#coupon_uuid').blur(function(){
		if($('#coupon_uuid').val().length!=0){
			loadCouponData();
		}else{
			$('#coupon_data').attr('class','msg rn');
			$('#coupon_data').html('请输入礼卷代码');
		}
	});

	$('#curl_btn').click(function(){
		if($('#url').val()!='')
			$('#rurl').text('${frontContextPath}/redirect.do?url='+$('#url').val()+'&site='+$('#asname').val());
		else
			$('#rurl').text('请输入转址目标');
	});

	$('#submit_button').click(function(){
		var isCorrect = true;
		$("span:[class=msg rn]").hide();
		$('#coupon_data').show();
		if($('#asname').val()==''){
			$('#nameTip').text('请输入渠道名称');
			$('#nameTip').show();
			isCorrect = false;
		}
		if($('#startDate').val()==''){
			$('#startDateTip').text('请输入起始日期');
			$('#startDateTip').show();
			isCorrect = false;
		}
		if($('#startTime').val()==''){
			$('#startTimeTip').text('请输入起始时间');
			$('#startTimeTip').show();
			isCorrect = false;
		}
		if($('#endDate').val()==''){
			$('#endDateTip').text('请输入结束日期');
			$('#endDateTip').show();
			isCorrect = false;
		}
		if($('#endTime').val()==''){
			$('#endTimeTip').text('请输入结束时间');
			$('#endTimeTip').show();
			isCorrect = false;
		}
		if($('#startDate').val()>$('#endDate').val()){
			$('#endDateTip').text('结束日期不能小于起始日期');
			$('#endDateTip').show();
			isCorrect = false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				$('#endTimeTip').text('结束时间需大于起始时间');
				$('#endTimeTip').show();
				isCorrect = false;
			}
		}
		if($('#radio_1').attr('checked')==true){
			if($('#coupon_data').html()==''){
				$('#coupon_data').attr('class','msg rn');
				$('#coupon_data').html('请输入礼卷代码');
				isCorrect = false;
			}
			if( $('#coupon_data').html()=='代码错误' || $('#coupon_data').html()=='请输入礼卷代码'){
				isCorrect = false;
			}
		}else if($('#radio_2').attr('checked')==true){
			if($('#amount').val()==''){
				$('#amountTip').text('请输入积分数');
				$('#amountTip').show();
				isCorrect = false;
			}else if($('#amount').val()==0){
				$('#amountTip').text('积分数不能为0');
				$('#amountTip').show();
				isCorrect = false;
			}
			if($('#after').val()==''){
				$('#afterTip').text('请输入积分几天后生效');
				$('#afterTip').show();
				isCorrect = false;
			}
			if($('#days').val()==''){
				$('#daysTip').text('请输入积分可使用天数');
				$('#daysTip').show();
				isCorrect = false;
			}else if($('#days').val()==0){
				$('#daysTip').text('可使用天数不能为0');
				$('#daysTip').show();
				isCorrect = false;
			}
		}
		if($('#memo').val()==''){
			$('#memoTip').text('请输入活动说明');
			$('#memoTip').show();
			isCorrect = false;
		}
		if(isCorrect){
			//alert('submit');
			$('#meForm').submit();
		}
	});
});

function loadCouponData(){
	$.post("<%=ServerValue.getMidContextPath()%>/memberevent/loadCouponData.do",{coupon_uuid:$('#coupon_uuid').val()},
			function callback(result){
				if(result == '代码错误'){
					$('#coupon_data').attr('class','msg rn');
				}else{
					$('#coupon_data').removeAttr('class');
				}
				$('#coupon_data').html(result);
			},
			"json");
}
</script>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror/>
<br/>
<h1>注册送积分或礼卷－编辑
<span class="f-link"><a href="${midContextPath}/memberevent/search.do">回列表</a></span>
</h1>
<s:form action="save.do" method="post" id="meForm">
	<table class="tb-data" width="100%">
		<tr>
			<th width="80">#</th>
			<td>${id}<input type="hidden" name="annId" value="${id}"></td>
		</tr>
		<tr>
			<th width="80">渠道名称</th>
			<td>
				<s:select id="asname" name="asname" list="channelNameMenu.options" listKey="key" listValue="value.name" value="%{asname}"/>
				<span id="nameTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th width="80">起始日期</th>
			<td>
				<input name="startDate" type="text" id="startDate"
				value="${startDate}" size="10" maxlength="10">
				<input id="startTime" name="startTime" type="text" value="${startTime}" maxlength="5" size="10" /><br/>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th width="80">结束日期</th>
			<td>
				<input name="endDate" type="text" id="endDate"
				value="${endDate}" size="10" maxlength="10">
				<input id="endTime" name="endTime" type="text" value="${endTime}" maxlength="5" size="10" /><br/>
				<span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th width="80">赠送类别</th>
			<td>
				<input type="radio" name="meType" value="1" id="radio_1" <c-rt:if test="${meType eq '1'}">checked="checked"</c-rt:if>/>礼卷 
				<input type="radio" name="meType" value="2" id="radio_2" <c-rt:if test="${meType eq '2'}">checked="checked"</c-rt:if>/>积分<br/>
			</td>
		</tr>
		<tr id="bonus" style="display:none;">
			<th width="80">积分</th>
			<td>
				<input id="amount" type="text" name="amount" value="${amount}" maxlength="5" size="10"/>积分
				<br/><span id="amountTip" class="msg rn" style="display:none;"></span>
				<br/><br/>几天后生效:<input id="after" type="text" name="after" value="${after}" maxlength="5" size="10"/>天
				<br/><span id="afterTip" class="msg rn" style="display:none;"></span>
				<br/><br/>积分可使用天数:<input id="days" type="text" name="days" value="${days}" maxlength="5" size="10"/>天
				<br/><span id="daysTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr id="coupon" style="display:none;">
			<th width="80">礼卷</th>
			<td>
				Coupon 代码： <input id="coupon_uuid" type="text" name="coupon_uuid" value="${coupon_uuid}" maxlength="40" size="50"/>
				<br/><span id="coupon_data"></span>
			</td>
		</tr>
		<tr>
			<th width="80">活动说明</th>
			<td>
				<input type="text" id="memo" name="memo" value="${memo}" maxlength="100"/><br/>
				<span id="memoTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<!-- 
		<tr>
			<th width="80">产生连结</th>
			<td>
				转址目标：<input type="text" id="url" maxlength="100" size="80" value="${frontContextPath}/" /><br/>
				<input type="button" id="curl_btn" value="产生转址连结"/>
				<br/>
				<span id="rurl"></span>
			</td>
		</tr>
		 -->
	</table>
	<br/>
	<input type="button" id="submit_button" value="送出"/>
	<input type="button" onclick="window.location='search.do'" value="Cancel"/>
</s:form>